package com.syw.houmao.main.main.model;

import com.syw.houmao.main.bean.FirstPagerCategory;
import com.syw.houmao.main.bean.Hot;
import com.syw.houmao.main.bean.IMyData;
import com.syw.houmao.main.path.Constant;

import java.io.IOException;

import retrofit2.Call;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by Administrator on 2016/10/19.
 */

public class DownLoadBiz implements IDownLoadBiz{


    @Override
    public Hot downLoadHot(String hotPath) {
        Retrofit retrofit =new Retrofit.Builder().
                baseUrl(hotPath)
                .addConverterFactory(GsonConverterFactory.create())
                .build();

        try {
            IMyData iMyData = retrofit.create(IMyData.class);
            Call<Hot> hotData = iMyData.getHotData();
            Hot body = hotData.execute().body();
            return body;
        } catch (IOException e) {
            e.printStackTrace();
        }
    return null;
    }

    @Override
    public FirstPagerCategory downLoadFirstPagerCategory(String categoryPath) {
        Retrofit retrofit = new Retrofit.Builder().baseUrl(categoryPath).
                addConverterFactory(GsonConverterFactory.create())
                .build();

        try {
            IMyData iMyData = retrofit.create(IMyData.class);
            Call<FirstPagerCategory> category = iMyData.getCategory();
            FirstPagerCategory body = category.execute().body();
            return body;
        } catch (IOException e) {
            e.printStackTrace();
        }
    return null;
    }

    @Override
    public void getdownLoadData(OnDownLoadListener listener) {
        listener.setFirstPagerCategory(downLoadFirstPagerCategory(Constant.CategoryPath));
        listener.setHot(downLoadHot(Constant.HotPath));
    }

}
